package com.api.shopapi.mapper;

import com.api.shopapi.entity.DeviceYjsbjian;
import com.api.shopapi.entity.DiseaseType;
import com.api.shopapi.entity.dto.DeviceYjsbjianDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface DiseaseTypeMapper {

    @Insert("insert into disease_type" +
            " (" +
            "DiseaseTypeCode," +
            "Name," +
            "Sort," +
            "Status," +
            "GovernmentCode," +
            "InstitutionCode" +
            ") values " +
            "(" +
            "#{diseaseType.DiseaseTypeCode}," +
            "#{diseaseType.Name}," +
            "#{diseaseType.Sort}," +
            "#{diseaseType.Status}," +
            "#{diseaseType.GovernmentCode}," +
            "#{diseaseType.InstitutionCode})")
    int insert(@Param("diseaseType") DiseaseType diseaseType);

    @Update("update disease_type" +
            " set" +
            " Name=#{diseaseType.Name}," +
            "Sort=#{diseaseType.Sort}," +
            "Status=#{diseaseType.Status}," +
            "InstitutionCode=#{diseaseType.InstitutionCode} " +
            "where DiseaseTypeCode=#{diseaseType.DiseaseTypeCode}")
    int update(@Param("diseaseType") DiseaseType diseaseType);

    @Select("select * from disease_type where diseaseTypeCode=#{diseaseTypeCode} limit 1")
    DiseaseType getByDiseaseTypeCode(@Param("diseaseTypeCode") String diseaseTypeCode);


    @Select("select * from disease_type where diseaseTypeName=#{diseaseTypeName} limit 1")
    DiseaseType getByDiseaseTypeName(@Param("diseaseTypeName") String diseaseTypeName);


    @Select("<script>" +
            "select * from disease_type " +
            " where institutionCode=#{institutionCode}" +
            " order by sort desc" +
            "</script>")
    List<DiseaseType> listByInsCode( @Param("institutionCode") String institutionCode);


    @Select("<script>" +
            "select * from disease_type " +
            " where institutionCode in (SELECT distinct institutionCode FROM institution where governmentCode=#{governmentCode})" +
            " order by sort desc" +
            "</script>")
    List<DiseaseType> listByGovCode( @Param("governmentCode") String governmentCode);



}
